package com.cat.bitOperation;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/xor-queries-of-a-subarray/description/
 * @create 2025/8/20 09:27
 * @since JDK17
 */

public class Solution02 {
    public int[] xorQueries(int[] arr, int[][] queries) {
        int n = arr.length, m = queries.length;
        int[] ans = new int[m], prefix = new int[n + 1];
        for (int i = 0; i < n; i++) {
            prefix[i + 1] = prefix[i] ^ arr[i];
        }

        for (int i = 0; i < m; i++) {
            ans[i] = prefix[queries[i][1] + 1] ^ prefix[queries[i][0]];
        }

        return ans;
    }
}
